<!DOCTYPE html>


<html lang="en">
  

    <head>
      <meta charset="utf-8" />
        
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title>linux内存管理--内核的shmall和shmmax参数 |  朝花夕拾</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/ww.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      
<link rel="stylesheet" href="/css/fonts/remixicon.css">

      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.staticfile.org/pace/1.2.4/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    </head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-linux内存管理-内核的shmall和shmmax参数"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  linux内存管理--内核的shmall和shmmax参数
</h1>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/07/03/linux%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86-%E5%86%85%E6%A0%B8%E7%9A%84shmall%E5%92%8Cshmmax%E5%8F%82%E6%95%B0/" class="article-date">
  <time datetime="2023-07-03T06:05:48.000Z" itemprop="datePublished">2023-07-03</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Linux/">Linux</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">6.9k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">26 min</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h3 id="linux-内存管理——内核的shmall-和shmmax-参数"><a href="#linux-内存管理——内核的shmall-和shmmax-参数" class="headerlink" title="linux 内存管理——内核的shmall 和shmmax 参数"></a>linux 内存管理——内核的shmall 和shmmax 参数</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br><span class="line">1. | 核心参数                                            | 最小建议值（不能小于此值） |</span><br><span class="line">   | --------------------------------------------------- | -------------------------- |</span><br><span class="line">   | SHMMAX (核所允许的最大单个共享内存段的大小(bytes) ) | 4398046511104              |</span><br><span class="line">   | SHMALL (整个系统的全部允许使用的共享内存大小(页) )  | 1073741824                 |</span><br><span class="line">   | SHMMNI (整个系统的共享内存段的最大数目(个)  )       | 4096                       |</span><br><span class="line">   |                                                     |                            |</span><br><span class="line">   | SEMMSL(每个信号量set中信号量最大个数)               | 250                        |</span><br><span class="line">   | SEMMNS(系统中信号量最大个数)                        | 32000                      |</span><br><span class="line">   | SEMOPM(每次semop系统调用允许的信号量最大个数)       | 100                        |</span><br><span class="line">   | SEMMNI(系统信号量set最大个数)                       | 128                        |</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">   #sem其实是semaphores的缩写，查看当前设置</span><br><span class="line">   $ cat /proc/sys/kernel/sem</span><br><span class="line">   250 32000 100 128</span><br><span class="line">   4个数据分别对应</span><br><span class="line">   SEMMSL SEMMNS SEMOPM SEMMNI</span><br><span class="line">   </span><br><span class="line">   SEMMSL</span><br><span class="line">   含义：每个信号量set中信号量最大个数 设置：最小250；对于processes参数设置较大的系统建议设置为processes+10</span><br><span class="line">   </span><br><span class="line">   SEMMNS</span><br><span class="line">   含义：linux系统中信号量最大个数 设置：至少32000；SEMMSL * SEMMNI</span><br><span class="line">   </span><br><span class="line">   SEMOPM</span><br><span class="line">   含义：semop系统调用允许的信号量最大个数 设置：至少100；或者等于SEMMSL</span><br><span class="line">   </span><br><span class="line">   SEMMNI</span><br><span class="line">   含义：linux系统信号量set最大个数 设置：最少128</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">   </span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br></pre></td><td class="code"><pre><span class="line">内核的 shmall 和 shmmax 参数</span><br><span class="line">SHMMAX= 配置了最大的内存segment的大小 ------&gt;这个设置的比SGA_MAX_SIZE大比较好。</span><br><span class="line"></span><br><span class="line">SHMMIN= 最小的内存segment的大小</span><br><span class="line"></span><br><span class="line">SHMMNI= 整个系统的内存segment的总个数</span><br><span class="line"></span><br><span class="line">SHMSEG= 每个进程可以使用的内存segment的最大个数</span><br><span class="line"></span><br><span class="line">配置信号灯（ semphore ）的参数：</span><br><span class="line"></span><br><span class="line">SEMMSL= 每个semphore set里面的semphore数量 -----&gt; 这个设置大于你的process的个数吧，否则你不得不分多个semphore set，好像有process+n之说，我忘了n是几了。</span><br><span class="line"></span><br><span class="line">SEMMNI= 整个系统的semphore set总数</span><br><span class="line"></span><br><span class="line">SEMMNS=整个系统的semphore总数</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">shmall 是全部允许使用的共享内存大小，shmmax 是单个段允许使用的大小。这两个可以设置为内存的 90%。例如 16G 内存，16*1024*1024*1024*90% = 15461882265，shmall 的大小为 15461882265/4k(getconf PAGESIZE可得到) = 3774873。</span><br><span class="line">修改 /etc/sysctl.conf</span><br><span class="line"></span><br><span class="line">kernel.shmmax=15461882265</span><br><span class="line"></span><br><span class="line">kernel.shmall=3774873</span><br><span class="line"></span><br><span class="line">kernel.msgmax=65535</span><br><span class="line"></span><br><span class="line">kernel.msgmnb=65535</span><br><span class="line"></span><br><span class="line">执行 sudo sysctl -p</span><br><span class="line"></span><br><span class="line">可以使用 ipcs -l 看结果。ipcs -u 可以看到实际使用的情况</span><br><span class="line"></span><br><span class="line">========================================================================</span><br><span class="line">linux 内存管理</span><br><span class="line"> </span><br><span class="line">一、前言</span><br><span class="line">本文档针对OOP8生产环境，具体优化策略需要根据实际情况进行调整；本文档将在以下几个方面来阐述如何针对RedHat Enterprise Linux进行性能优化。</span><br><span class="line">1)     Linux Proc文件系统，通过对Proc文件系统进行调整，达到性能优化的目的。</span><br><span class="line">2)     Linux性能诊断工具，介绍如何使用Linux自带的诊断工具进行性能诊断。</span><br><span class="line">加粗斜体表示可以直接运行的命令。</span><br><span class="line">下划线表示文件的内容。</span><br><span class="line">二、/proc/sys/kernel/优化</span><br><span class="line">1)     /proc/sys/kernel/ctrl-alt-del</span><br><span class="line">该文件有一个二进制值，该值控制系统在接收到ctrl+alt+delete按键组合时如何反应。这两个值分别是：</span><br><span class="line">零（0）值，表示捕获ctrl+alt+delete，并将其送至 init 程序；这将允许系统可以安全地关闭和重启，就好象输入shutdown命令一样。</span><br><span class="line">壹（1）值，表示不捕获ctrl+alt+delete，将执行非正常的关闭，就好象直接关闭电源一样。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">建议设置：1，防止意外按下ctrl+alt+delete导致系统非正常重启。</span><br><span class="line">2)     proc/sys/kernel/msgmax</span><br><span class="line">该文件指定了从一个进程发送到另一个进程的消息的最大长度（bytes）。进程间的消息传递是在内核的内存中进行的，不会交换到磁盘上，所以如果增加该值，则将增加操作系统所使用的内存数量。</span><br><span class="line"></span><br><span class="line">缺省设置：8192</span><br><span class="line">3)     /proc/sys/kernel/msgmnb</span><br><span class="line">该文件指定一个消息队列的最大长度（bytes）。</span><br><span class="line"></span><br><span class="line">缺省设置：16384</span><br><span class="line">4)     /proc/sys/kernel/msgmni</span><br><span class="line">该文件指定消息队列标识的最大数目，即系统范围内最大多少个消息队列。</span><br><span class="line"></span><br><span class="line">缺省设置：16</span><br><span class="line">5)     /proc/sys/kernel/panic</span><br><span class="line">该文件表示如果发生“内核严重错误（kernel panic）”，则内核在重新引导之前等待的时间（以秒为单位）。</span><br><span class="line">零（0）秒，表示在发生内核严重错误时将禁止自动重新引导。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">6)     proc/sys/kernel/shmall</span><br><span class="line">该文件表示在任何给定时刻，系统上可以使用的共享内存的总量（bytes）。</span><br><span class="line"></span><br><span class="line">缺省设置：2097152</span><br><span class="line">7)     /proc/sys/kernel/shmmax</span><br><span class="line">该文件表示内核所允许的最大共享内存段的大小（bytes）。</span><br><span class="line"></span><br><span class="line">缺省设置：33554432</span><br><span class="line">建议设置：物理内存 * 50%</span><br><span class="line"></span><br><span class="line">实际可用最大共享内存段大小=shmmax * 98%，其中大约2%用于共享内存结构。</span><br><span class="line">可以通过设置shmmax，然后执行ipcs -l来验证。</span><br><span class="line">8)     /proc/sys/kernel/shmmni</span><br><span class="line">该文件表示用于整个系统的共享内存段的最大数目（个）。</span><br><span class="line"></span><br><span class="line">缺省设置：4096</span><br><span class="line">9)     /proc/sys/kernel/threads-max</span><br><span class="line">该文件表示内核所能使用的线程的最大数目。</span><br><span class="line"></span><br><span class="line">缺省设置：2048</span><br><span class="line">10) /proc/sys/kernel/sem</span><br><span class="line">该文件用于控制内核信号量，信号量是System VIPC用于进程间通讯的方法。</span><br><span class="line"></span><br><span class="line">建议设置：250 32000 100 128</span><br><span class="line">第一列，表示每个信号集中的最大信号量数目。</span><br><span class="line">第二列，表示系统范围内的最大信号量总数目。</span><br><span class="line">第三列，表示每个信号发生时的最大系统操作数目。</span><br><span class="line">第四列，表示系统范围内的最大信号集总数目。</span><br><span class="line">所以，（第一列）*（第四列）=（第二列）</span><br><span class="line"></span><br><span class="line">以上设置，可以通过执行ipcs -l来验证。</span><br><span class="line">11) 待续。。。</span><br><span class="line">三、/proc/sys/vm/优化</span><br><span class="line">1)     /proc/sys/vm/block_dump</span><br><span class="line">该文件表示是否打开Block Debug模式，用于记录所有的读写及Dirty Block写回动作。</span><br><span class="line"></span><br><span class="line">缺省设置：0，禁用Block Debug模式</span><br><span class="line">2)     /proc/sys/vm/dirty_background_ratio</span><br><span class="line">该文件表示脏数据到达系统整体内存的百分比，此时触发pdflush进程把脏数据写回磁盘。</span><br><span class="line"></span><br><span class="line">缺省设置：10</span><br><span class="line">3)     /proc/sys/vm/dirty_expire_centisecs</span><br><span class="line">该文件表示如果脏数据在内存中驻留时间超过该值，pdflush进程在下一次将把这些数据写回磁盘。</span><br><span class="line"></span><br><span class="line">缺省设置：3000（1/100秒）</span><br><span class="line">4)     /proc/sys/vm/dirty_ratio</span><br><span class="line">该文件表示如果进程产生的脏数据到达系统整体内存的百分比，此时进程自行把脏数据写回磁盘。</span><br><span class="line"></span><br><span class="line">缺省设置：40</span><br><span class="line">5)     /proc/sys/vm/dirty_writeback_centisecs</span><br><span class="line">该文件表示pdflush进程周期性间隔多久把脏数据写回磁盘。</span><br><span class="line"></span><br><span class="line">缺省设置：500（1/100秒）</span><br><span class="line">6)     /proc/sys/vm/vfs_cache_pressure</span><br><span class="line">该文件表示内核回收用于directory和inode cache内存的倾向；缺省值100表示内核将根据pagecache和swapcache，把directory和inode cache保持在一个合理的百分比；降低该值低于100，将导致内核倾向于保留directory和inode cache；增加该值超过100，将导致内核倾向于回收directory和inode cache。</span><br><span class="line"></span><br><span class="line">缺省设置：100</span><br><span class="line">7)     /proc/sys/vm/min_free_kbytes</span><br><span class="line">该文件表示强制Linux VM最低保留多少空闲内存（Kbytes）。</span><br><span class="line"></span><br><span class="line">缺省设置：724（512M物理内存）</span><br><span class="line">8)     /proc/sys/vm/nr_pdflush_threads</span><br><span class="line">该文件表示当前正在运行的pdflush进程数量，在I/O负载高的情况下，内核会自动增加更多的pdflush进程。</span><br><span class="line"></span><br><span class="line">缺省设置：2（只读）</span><br><span class="line">9)     /proc/sys/vm/overcommit_memory</span><br><span class="line">该文件指定了内核针对内存分配的策略，其值可以是0、1、2。</span><br><span class="line">0， 表示内核将检查是否有足够的可用内存供应用进程使用；如果有足够的可用内存，内存申请允许；否则，内存申请失败，并把错误返回给应用进程。</span><br><span class="line">1， 表示内核允许分配所有的物理内存，而不管当前的内存状态如何。</span><br><span class="line">2， 表示内核允许分配超过所有物理内存和交换空间总和的内存（参照overcommit_ratio）。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">10) /proc/sys/vm/overcommit_ratio</span><br><span class="line">该文件表示，如果overcommit_memory=2，可以过载内存的百分比，通过以下公式来计算系统整体可用内存。</span><br><span class="line">系统可分配内存=交换空间+物理内存*overcommit_ratio/100</span><br><span class="line"></span><br><span class="line">缺省设置：50（%）</span><br><span class="line">11) /proc/sys/vm/page-cluster</span><br><span class="line">该文件表示在写一次到swap区的时候写入的页面数量，0表示1页，1表示2页，2表示4页。</span><br><span class="line"></span><br><span class="line">缺省设置：3（2的3次方，8页）</span><br><span class="line">12) /proc/sys/vm/swapiness</span><br><span class="line">该文件表示系统进行交换行为的程度，数值（0-100）越高，越可能发生磁盘交换。</span><br><span class="line"></span><br><span class="line">缺省设置：60</span><br><span class="line">13) legacy_va_layout</span><br><span class="line">该文件表示是否使用最新的32位共享内存mmap()系统调用，Linux支持的共享内存分配方式包括mmap()，Posix，System VIPC。</span><br><span class="line">0， 使用最新32位mmap()系统调用。</span><br><span class="line">1， 使用2.4内核提供的系统调用。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">14) nr_hugepages</span><br><span class="line">该文件表示系统保留的hugetlb页数。</span><br><span class="line">15) hugetlb_shm_group</span><br><span class="line">该文件表示允许使用hugetlb页创建System VIPC共享内存段的系统组ID。</span><br><span class="line">16) 待续。。。</span><br><span class="line">四、/proc/sys/fs/优化</span><br><span class="line">1)     /proc/sys/fs/file-max</span><br><span class="line">该文件指定了可以分配的文件句柄的最大数目。如果用户得到的错误消息声明由于打开</span><br><span class="line">文件数已经达到了最大值，从而他们不能打开更多文件，则可能需要增加该值。</span><br><span class="line"></span><br><span class="line">缺省设置：4096</span><br><span class="line">建议设置：65536</span><br><span class="line">2)     /proc/sys/fs/file-nr</span><br><span class="line">该文件与 file-max 相关，它有三个值：</span><br><span class="line">已分配文件句柄的数目</span><br><span class="line">已使用文件句柄的数目</span><br><span class="line">文件句柄的最大数目</span><br><span class="line">该文件是只读的，仅用于显示信息。</span><br><span class="line">3)     待续。。。</span><br><span class="line">五、/proc/sys/net/core/优化</span><br><span class="line">该目录下的配置文件主要用来控制内核和网络层之间的交互行为。</span><br><span class="line">1） /proc/sys/net/core/message_burst</span><br><span class="line">写新的警告消息所需的时间（以 1/10 秒为单位）；在这个时间内系统接收到的其它警告消息会被丢弃。这用于防止某些企图用消息“淹没”系统的人所使用的拒绝服务（Denial of Service）攻击。</span><br><span class="line"></span><br><span class="line">缺省设置：50（5秒）</span><br><span class="line">2） /proc/sys/net/core/message_cost</span><br><span class="line">该文件表示写每个警告消息相关的成本值。该值越大，越有可能忽略警告消息。</span><br><span class="line"></span><br><span class="line">缺省设置：5</span><br><span class="line">3） /proc/sys/net/core/netdev_max_backlog</span><br><span class="line">该文件表示在每个网络接口接收数据包的速率比内核处理这些包的速率快时，允许送到队列的数据包的最大数目。</span><br><span class="line"></span><br><span class="line">缺省设置：300</span><br><span class="line">4） /proc/sys/net/core/optmem_max</span><br><span class="line">该文件表示每个套接字所允许的最大缓冲区的大小。</span><br><span class="line"></span><br><span class="line">缺省设置：10240</span><br><span class="line">5） /proc/sys/net/core/rmem_default</span><br><span class="line">该文件指定了接收套接字缓冲区大小的缺省值（以字节为单位）。</span><br><span class="line"></span><br><span class="line">缺省设置：110592</span><br><span class="line">6） /proc/sys/net/core/rmem_max</span><br><span class="line">该文件指定了接收套接字缓冲区大小的最大值（以字节为单位）。</span><br><span class="line"></span><br><span class="line">缺省设置：131071</span><br><span class="line">7） /proc/sys/net/core/wmem_default</span><br><span class="line">该文件指定了发送套接字缓冲区大小的缺省值（以字节为单位）。</span><br><span class="line"></span><br><span class="line">缺省设置：110592</span><br><span class="line">8） /proc/sys/net/core/wmem_max</span><br><span class="line">该文件指定了发送套接字缓冲区大小的最大值（以字节为单位）。</span><br><span class="line"></span><br><span class="line">缺省设置：131071</span><br><span class="line">9） 待续。。。</span><br><span class="line">六、/proc/sys/net/ipv4/优化</span><br><span class="line">1)     /proc/sys/net/ipv4/ip_forward</span><br><span class="line">该文件表示是否打开IP转发。</span><br><span class="line">0，禁止</span><br><span class="line">1，转发</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">2)     /proc/sys/net/ipv4/ip_default_ttl</span><br><span class="line">该文件表示一个数据报的生存周期（Time To Live），即最多经过多少路由器。</span><br><span class="line"></span><br><span class="line">缺省设置：64</span><br><span class="line">增加该值会降低系统性能。</span><br><span class="line">3)     /proc/sys/net/ipv4/ip_no_pmtu_disc</span><br><span class="line">该文件表示在全局范围内关闭路径MTU探测功能。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">4)     /proc/sys/net/ipv4/route/min_pmtu</span><br><span class="line">该文件表示最小路径MTU的大小。</span><br><span class="line"></span><br><span class="line">缺省设置：552</span><br><span class="line">5)     /proc/sys/net/ipv4/route/mtu_expires</span><br><span class="line">该文件表示PMTU信息缓存多长时间（秒）。</span><br><span class="line"></span><br><span class="line">缺省设置：600（秒）</span><br><span class="line">6)     /proc/sys/net/ipv4/route/min_adv_mss</span><br><span class="line">该文件表示最小的MSS（Maximum Segment Size）大小，取决于第一跳的路由器MTU。</span><br><span class="line"></span><br><span class="line">缺省设置：256（bytes）</span><br><span class="line">6.1 IP Fragmentation</span><br><span class="line">1)     /proc/sys/net/ipv4/ipfrag_low_thresh/proc/sys/net/ipv4/ipfrag_low_thresh</span><br><span class="line">两个文件分别表示用于重组IP分段的内存分配最低值和最高值，一旦达到最高内存分配值，其它分段将被丢弃，直到达到最低内存分配值。</span><br><span class="line"></span><br><span class="line">缺省设置：196608（ipfrag_low_thresh）</span><br><span class="line">262144（ipfrag_high_thresh）</span><br><span class="line">2)     /proc/sys/net/ipv4/ipfrag_time</span><br><span class="line">该文件表示一个IP分段在内存中保留多少秒。</span><br><span class="line"></span><br><span class="line">缺省设置：30（秒）</span><br><span class="line">6.2 INET Peer Storage</span><br><span class="line">1)     /proc/sys/net/ipv4/inet_peer_threshold</span><br><span class="line">INET对端存储器某个合适值，当超过该阀值条目将被丢弃。该阀值同样决定生存</span><br><span class="line">时间以及废物收集通过的时间间隔。条目越多，存活期越低，GC 间隔越短。</span><br><span class="line"></span><br><span class="line">缺省设置：65664</span><br><span class="line">2)     /proc/sys/net/ipv4/inet_peer_minttl</span><br><span class="line">条目的最低存活期。在重组端必须要有足够的碎片(fragment)存活期。这个最低</span><br><span class="line">存活期必须保证缓冲池容积是否少于 inet_peer_threshold。该值以 jiffies为</span><br><span class="line">单位测量。</span><br><span class="line"></span><br><span class="line">缺省设置：120</span><br><span class="line">3)     /proc/sys/net/ipv4/inet_peer_maxttl</span><br><span class="line">条目的最大存活期。在此期限到达之后，如果缓冲池没有耗尽压力的话(例如：缓</span><br><span class="line">冲池中的条目数目非常少)，不使用的条目将会超时。该值以 jiffies为单位测量。</span><br><span class="line"></span><br><span class="line">缺省设置：600</span><br><span class="line">4)     /proc/sys/net/ipv4/inet_peer_gc_mintime</span><br><span class="line">废物收集(GC)通过的最短间隔。这个间隔会影响到缓冲池中内存的高压力。 该值</span><br><span class="line">以 jiffies为单位测量。</span><br><span class="line"></span><br><span class="line">缺省设置：10</span><br><span class="line"></span><br><span class="line">2006-10-31 16:33 清水飘萍</span><br><span class="line">5)     /proc/sys/net/ipv4/inet_peer_gc_maxtime</span><br><span class="line">废物收集(GC)通过的最大间隔，这个间隔会影响到缓冲池中内存的低压力。 该值</span><br><span class="line">以 jiffies为单位测量。</span><br><span class="line"></span><br><span class="line">缺省设置：120</span><br><span class="line">6.3 TCP Variables</span><br><span class="line">1)     /proc/sys/net/ipv4/tcp_syn_retries</span><br><span class="line">该文件表示本机向外发起TCP SYN连接超时重传的次数，不应该高于255；该值仅仅针对外出的连接，对于进来的连接由tcp_retries1控制。</span><br><span class="line"></span><br><span class="line">缺省设置：5</span><br><span class="line">2)     /proc/sys/net/ipv4/tcp_keepalive_probes</span><br><span class="line">该文件表示丢弃TCP连接前，进行最大TCP保持连接侦测的次数。保持连接仅在</span><br><span class="line">SO_KEEPALIVE套接字选项被打开时才被发送。</span><br><span class="line"></span><br><span class="line">缺省设置：9（次）</span><br><span class="line">3)     /proc/sys/net/ipv4/tcp_keepalive_time</span><br><span class="line">该文件表示从不再传送数据到向连接上发送保持连接信号之间所需的秒数。</span><br><span class="line"></span><br><span class="line">缺省设置：7200（2小时）</span><br><span class="line">4)     /proc/sys/net/ipv4/tcp_keepalive_intvl</span><br><span class="line">该文件表示发送TCP探测的频率，乘以tcp_keepalive_probes表示断开没有相应的TCP连接的时间。</span><br><span class="line"></span><br><span class="line">缺省设置：75（秒）</span><br><span class="line">5)     /proc/sys/net/ipv4/tcp_retries1</span><br><span class="line">该文件表示放弃回应一个TCP连接请求前进行重传的次数。</span><br><span class="line"></span><br><span class="line">缺省设置：3</span><br><span class="line">6)     /proc/sys/net/ipv4/tcp_retries2</span><br><span class="line">该文件表示放弃在已经建立通讯状态下的一个TCP数据包前进行重传的次数。</span><br><span class="line"></span><br><span class="line">缺省设置：15</span><br><span class="line">7)     /proc/sys/net/ipv4/tcp_orphan_retries</span><br><span class="line">在近端丢弃TCP连接之前，要进行多少次重试。默认值是 7 个，相当于 50秒–</span><br><span class="line">16分钟，视 RTO 而定。如果您的系统是负载很大的web服务器，那么也许需</span><br><span class="line">要降低该值，这类 sockets 可能会耗费大量的资源。另外参考</span><br><span class="line">tcp_max_orphans。</span><br><span class="line">8)     /proc/sys/net/ipv4/tcp_fin_timeout</span><br><span class="line">对于本端断开的socket连接，TCP保持在FIN-WAIT-2状态的时间。对方可能</span><br><span class="line">会断开连接或一直不结束连接或不可预料的进程死亡。默认值为 60 秒。过去在</span><br><span class="line">2.2版本的内核中是 180 秒。您可以设置该值，但需要注意，如果您的机器为负</span><br><span class="line">载很重的web服务器，您可能要冒内存被大量无效数据报填满的风险，</span><br><span class="line">FIN-WAIT-2 sockets 的危险性低于 FIN-WAIT-1，因为它们最多只吃 1.5K</span><br><span class="line">的内存，但是它们存在时间更长。另外参考 tcp_max_orphans。</span><br><span class="line"></span><br><span class="line">缺省设置：60（秒）</span><br><span class="line">9)     /proc/sys/net/ipv4/tcp_max_tw_buckets</span><br><span class="line">系统在同时所处理的最大timewait sockets 数目。如果超过此数的话，</span><br><span class="line">time-wait socket 会被立即砍除并且显示警告信息。之所以要设定这个限制，纯</span><br><span class="line">粹为了抵御那些简单的 DoS 攻击，千万不要人为的降低这个限制，不过，如果</span><br><span class="line">网络条件需要比默认值更多，则可以提高它(或许还要增加内存)。</span><br><span class="line"></span><br><span class="line">缺省设置：180000</span><br><span class="line">10) /proc/sys/net/ipv4/tcp_tw_recyle</span><br><span class="line">打开快速 TIME-WAIT sockets 回收。除非得到技术专家的建议或要求，请不要随</span><br><span class="line">意修改这个值。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">11) /proc/sys/net/ipv4/tcp_tw_reuse</span><br><span class="line">该文件表示是否允许重新应用处于TIME-WAIT状态的socket用于新的TCP连接。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">12) /proc/sys/net/ipv4/tcp_max_orphans</span><br><span class="line">系统所能处理不属于任何进程的TCP sockets最大数量。假如超过这个数量，那</span><br><span class="line">么不属于任何进程的连接会被立即reset，并同时显示警告信息。之所以要设定这</span><br><span class="line">个限制，纯粹为了抵御那些简单的 DoS 攻击，千万不要依赖这个或是人为的降</span><br><span class="line">低这个限制。</span><br><span class="line"></span><br><span class="line">缺省设置：8192</span><br><span class="line">13) /proc/sys/net/ipv4/tcp_abort_on_overflow</span><br><span class="line">当守护进程太忙而不能接受新的连接，就向对方发送reset消息，默认值是false。</span><br><span class="line">这意味着当溢出的原因是因为一个偶然的猝发，那么连接将恢复状态。只有在你确</span><br><span class="line">信守护进程真的不能完成连接请求时才打开该选项，该选项会影响客户的使用。</span><br><span class="line"></span><br><span class="line">缺省设置：０</span><br><span class="line">14) /proc/sys/net/ipv4/tcp_syncookies</span><br><span class="line">该文件表示是否打开TCP同步标签(syncookie)，内核必须打开了 CONFIG_SYN_COOKIES项进行编译。 同步标签(syncookie)可以防止一个套接字在有过多试图连接到达时引起过载。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">15) /proc/sys/net/ipv4/tcp_stdurg</span><br><span class="line">使用 TCP urg pointer 字段中的主机请求解释功能。大部份的主机都使用老旧的</span><br><span class="line">BSD解释，因此如果您在 Linux 打开它，或会导致不能和它们正确沟通。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">16) /proc/sys/net/ipv4/tcp_max_syn_backlog</span><br><span class="line">对于那些依然还未获得客户端确认的连接请求，需要保存在队列中最大数目。对于</span><br><span class="line">超过 128Mb 内存的系统，默认值是 1024，低于 128Mb 的则为 128。如果</span><br><span class="line">服务器经常出现过载，可以尝试增加这个数字。警告！假如您将此值设为大于</span><br><span class="line">1024，最好修改 include/net/tcp.h 里面的 TCP_SYNQ_HSIZE，以保持</span><br><span class="line">TCP_SYNQ_HSIZE*16 0)或者bytes-bytes/2^(-tcp_adv_win_scale)(如</span><br><span class="line">果tcp_adv_win_scale 128Mb 32768-610000)则系统将忽略所有发送给自己</span><br><span class="line">的ICMP ECHO请求或那些广播地址的请求。</span><br><span class="line"></span><br><span class="line">缺省设置：1024</span><br><span class="line">17) /proc/sys/net/ipv4/tcp_window_scaling</span><br><span class="line">该文件表示设置tcp/ip会话的滑动窗口大小是否可变。参数值为布尔值，为1时表示可变，为0时表示不可变。tcp/ip通常使用的窗口最大可达到 65535 字节，对于高速网络，该值可能太小，这时候如果启用了该功能，可以使tcp/ip滑动窗口大小增大数个数量级，从而提高数据传输的能力。</span><br><span class="line"></span><br><span class="line">缺省设置：1</span><br><span class="line">18) /proc/sys/net/ipv4/tcp_sack</span><br><span class="line">该文件表示是否启用有选择的应答（Selective Acknowledgment），这可以通过有选择地应答乱序接收到的报文来提高性能（这样可以让发送者只发送丢失的报文段）；（对于广域网通信来说）这个选项应该启用，但是这会增加对 CPU 的占用。</span><br><span class="line"></span><br><span class="line">缺省设置：1</span><br><span class="line">19) /proc/sys/net/ipv4/tcp_timestamps</span><br><span class="line">该文件表示是否启用以一种比超时重发更精确的方法（请参阅 RFC 1323）来启用对 RTT 的计算；为了实现更好的性能应该启用这个选项。</span><br><span class="line"></span><br><span class="line">缺省设置：1</span><br><span class="line">20) /proc/sys/net/ipv4/tcp_fack</span><br><span class="line">该文件表示是否打开FACK拥塞避免和快速重传功能。</span><br><span class="line"></span><br><span class="line">缺省设置：1</span><br><span class="line">21) /proc/sys/net/ipv4/tcp_dsack</span><br><span class="line">该文件表示是否允许TCP发送“两个完全相同”的SACK。</span><br><span class="line"></span><br><span class="line">缺省设置：1</span><br><span class="line">22) /proc/sys/net/ipv4/tcp_ecn</span><br><span class="line">该文件表示是否打开TCP的直接拥塞通告功能。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">23) /proc/sys/net/ipv4/tcp_reordering</span><br><span class="line">该文件表示TCP流中重排序的数据报最大数量。</span><br><span class="line"></span><br><span class="line">缺省设置：3</span><br><span class="line">24) /proc/sys/net/ipv4/tcp_retrans_collapse</span><br><span class="line">该文件表示对于某些有bug的打印机是否提供针对其bug的兼容性。</span><br><span class="line"></span><br><span class="line">缺省设置：1</span><br><span class="line">25) /proc/sys/net/ipv4/tcp_wmem</span><br><span class="line">该文件包含3个整数值，分别是：min，default，max</span><br><span class="line">Min：为TCP socket预留用于发送缓冲的内存最小值。每个TCP socket都可以使用它。</span><br><span class="line">Default：为TCP socket预留用于发送缓冲的内存数量，默认情况下该值会影响其它协议使用的net.core.wmem中default的 值，一般要低于net.core.wmem中default的值。</span><br><span class="line">Max：为TCP socket预留用于发送缓冲的内存最大值。该值不会影响net.core.wmem_max，今天选择参数SO_SNDBUF则不受该值影响。默认值为128K。</span><br><span class="line"></span><br><span class="line">缺省设置：4096 16384 131072</span><br><span class="line">26) /proc/sys/net/ipv4/tcp_rmem</span><br><span class="line">该文件包含3个整数值，分别是：min，default，max</span><br><span class="line">Min：为TCP socket预留用于接收缓冲的内存数量，即使在内存出现紧张情况下TCP socket都至少会有这么多数量的内存用于接收缓冲。</span><br><span class="line">Default：为TCP socket预留用于接收缓冲的内存数量，默认情况下该值影响其它协议使用的 net.core.wmem中default的值。该值决定了在tcp_adv_win_scale、tcp_app_win和tcp_app_win的 默认值情况下，TCP 窗口大小为65535。</span><br><span class="line">Max：为TCP socket预留用于接收缓冲的内存最大值。该值不会影响 net.core.wmem中max的值，今天选择参数 SO_SNDBUF则不受该值影响。</span><br><span class="line"></span><br><span class="line">缺省设置：4096 87380 174760</span><br><span class="line">27) /proc/sys/net/ipv4/tcp_mem</span><br><span class="line">该文件包含3个整数值，分别是：low，pressure，high</span><br><span class="line">Low：当TCP使用了低于该值的内存页面数时，TCP不会考虑释放内存。</span><br><span class="line">Pressure：当TCP使用了超过该值的内存页面数量时，TCP试图稳定其内存使用，进入pressure模式，当内存消耗低于low值时则退出pressure状态。</span><br><span class="line">High：允许所有tcp sockets用于排队缓冲数据报的页面量。</span><br><span class="line">一般情况下这些值是在系统启动时根据系统内存数量计算得到的。</span><br><span class="line"></span><br><span class="line">缺省设置：24576 32768 49152</span><br><span class="line">28) /proc/sys/net/ipv4/tcp_app_win</span><br><span class="line">该文件表示保留max(window/2^tcp_app_win, mss)数量的窗口由于应用缓冲。当为0时表示不需要缓冲。</span><br><span class="line"></span><br><span class="line">缺省设置：31</span><br><span class="line">29) /proc/sys/net/ipv4/tcp_adv_win_scale</span><br><span class="line">该文件表示计算缓冲开销bytes/2^tcp_adv_win_scale(如果tcp_adv_win_scale &gt;; 0)或者bytes-bytes/2^(-tcp_adv_win_scale)(如果tcp_adv_win_scale &lt;= 0）。</span><br><span class="line"></span><br><span class="line">缺省设置：2</span><br><span class="line">6.4 IP Variables</span><br><span class="line">1)     /proc/sys/net/ipv4/ip_local_port_range</span><br><span class="line">该文件表示TCP／UDP协议打开的本地端口号。</span><br><span class="line"></span><br><span class="line">缺省设置：1024 4999</span><br><span class="line">建议设置：32768 61000</span><br><span class="line">2)     /proc/sys/net/ipv4/ip_nonlocal_bind</span><br><span class="line">该文件表示是否允许进程邦定到非本地地址。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">3)     /proc/sys/net/ipv4/ip_dynaddr</span><br><span class="line">该参数通常用于使用拨号连接的情况，可以使系统动能够立即改变ip包的源地址为该ip地址，同时中断原有的tcp对话而用新地址重新发出一个syn请求 包，开始新的tcp对话。在使用ip欺骗时，该参数可以立即改变伪装地址为新的ip地址。该文件表示是否允许动态地址，如果该值非0，表示允许；如果该值 大于1，内核将通过log记录动态地址重写信息。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">4)     /proc/sys/net/ipv4/icmp_echo_ignore_all/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts</span><br><span class="line">该文件表示内核是否忽略所有的ICMP ECHO请求，或忽略广播和多播请求。</span><br><span class="line">0， 响应请求</span><br><span class="line">1， 忽略请求</span><br><span class="line"></span><br><span class="line">缺省设置：０</span><br><span class="line">建议设置：1</span><br><span class="line">5)     /proc/sys/net/ipv4/icmp_ratelimit</span><br><span class="line">6)     /proc/sys/net/ipv4/icmp_ratemask</span><br><span class="line">7)     /proc/sys/net/ipv4/icmp_ignore_bogus_error_reponses</span><br><span class="line">某些路由器违背RFC1122标准，其对广播帧发送伪造的响应来应答。这种违背行</span><br><span class="line">为通常会被以告警的方式记录在系统日志中。如果该选项设置为True，内核不会</span><br><span class="line">记录这种警告信息。</span><br><span class="line"></span><br><span class="line">缺省设置：0</span><br><span class="line">8)     /proc/sys/net/ipv4/igmp_max_memberships</span><br><span class="line">该文件表示多播组中的最大成员数量。</span><br><span class="line"></span><br><span class="line">缺省设置：20</span><br><span class="line">6.5 Other Configuration</span><br><span class="line">1)     /proc/sys/net/ipv4/conf/*/accept_redirects</span><br><span class="line">如果主机所在的网段中有两个路由器，你将其中一个设置成了缺省网关，但是该网关</span><br><span class="line">在收到你的ip包时发现该ip包必须经过另外一个路由器，这时这个路由器就会给你</span><br><span class="line">发一个所谓的“重定向”icmp包，告诉将ip包转发到另外一个路由器。参数值为布尔</span><br><span class="line">值，1表示接收这类重定向icmp 信息，0表示忽略。在充当路由器的linux主机上缺</span><br><span class="line">省值为0，在一般的linux主机上缺省值为1。建议将其改为0以消除安全性隐患。</span><br><span class="line">2)     /proc/sys/net/ipv4/*/accept_source_route</span><br><span class="line">是否接受含有源路由信息的ip包。参数值为布尔值，1表示接受，0表示不接受。在</span><br><span class="line">充当网关的linux主机上缺省值为1，在一般的linux主机上缺省值为0。从安全性角</span><br><span class="line">度出发，建议关闭该功能。</span><br><span class="line">3)     /proc/sys/net/ipv4/*/secure_redirects</span><br><span class="line">其实所谓的“安全重定向”就是只接受来自网关的“重定向”icmp包。该参数就是</span><br><span class="line">用来设置“安全重定向”功能的。参数值为布尔值，1表示启用，0表示禁止，缺省值</span><br><span class="line">为启用。</span><br><span class="line">4)     /proc/sys/net/ipv4/*/proxy_arp</span><br><span class="line">设置是否对网络上的arp包进行中继。参数值为布尔值，1表示中继，0表示忽略，</span><br><span class="line">缺省值为0。该参数通常只对充当路由器的linux主机有用。</span><br><span class="line">七、性能优化策略</span><br><span class="line">7.1 基本优化</span><br><span class="line">1)     关闭后台守护进程</span><br><span class="line">系统安装完后，系统会默认启动一些后台守护进程，有些进程并不是必需的；因此，关闭这些进程可以节省一部分物理内存消耗。以root身份登录系统，运行ntsysv，选中如下进程：</span><br><span class="line">iptables</span><br><span class="line">network</span><br><span class="line">syslog</span><br><span class="line">random</span><br><span class="line">apmd</span><br><span class="line">xinetd</span><br><span class="line">vsftpd</span><br><span class="line">crond</span><br><span class="line">local</span><br><span class="line">修改完后，重新启动系统。</span><br><span class="line">如此，系统将仅仅启动选中的这些守护进程。</span><br><span class="line">2)     减少终端连接数</span><br><span class="line">系统默认启动6个终端，而实际上只需启动3个即可；以root身份登录系统，运行vi /etc/inittab，修改成如下：</span><br><span class="line"># Run gettys in standard runlevels</span><br><span class="line">1:2345:respawn:/sbin/mingetty tty1</span><br><span class="line">2:2345:respawn:/sbin/mingetty tty2</span><br><span class="line">3:2345:respawn:/sbin/mingetty tty3</span><br><span class="line">#4:2345:respawn:/sbin/mingetty tty4</span><br><span class="line">#5:2345:respawn:/sbin/mingetty tty5</span><br><span class="line">#6:2345:respawn:/sbin/mingetty tty6</span><br><span class="line">如上所述，注释掉4、5、6终端。</span><br><span class="line">3)     待续。。。</span><br><span class="line">7.2 网络优化</span><br><span class="line">1)     优化系统套接字缓冲区</span><br><span class="line">net.core.rmem_max=16777216</span><br><span class="line">net.core.wmem_max=16777216</span><br><span class="line">2)     优化TCP接收／发送缓冲区</span><br><span class="line">net.ipv4.tcp_rmem=4096 87380 16777216</span><br><span class="line">net.ipv4.tcp_wmem=4096 65536 16777216</span><br><span class="line">3)     优化网络设备接收队列</span><br><span class="line">net.core.netdev_max_backlog=3000</span><br><span class="line">4)     关闭路由相关功能</span><br><span class="line">net.ipv4.conf.lo.accept_source_route=0</span><br><span class="line">net.ipv4.conf.all.accept_source_route=0</span><br><span class="line">net.ipv4.conf.eth0.accept_source_route=0</span><br><span class="line">net.ipv4.conf.default.accept_source_route=0</span><br><span class="line"></span><br><span class="line">net.ipv4.conf.lo.accept_redirects=0</span><br><span class="line">net.ipv4.conf.all.accept_redirects=0</span><br><span class="line">net.ipv4.conf.eth0.accept_redirects=0</span><br><span class="line">net.ipv4.conf.default.accept_redirects=0</span><br><span class="line"></span><br><span class="line">net.ipv4.conf.lo.secure_redirects=0</span><br><span class="line">net.ipv4.conf.all.secure_redirects=0</span><br><span class="line">net.ipv4.conf.eth0.secure_redirects=0</span><br><span class="line">net.ipv4.conf.default.secure_redirects=0</span><br><span class="line"></span><br><span class="line">net.ipv4.conf.lo.send_redirects=0</span><br><span class="line">net.ipv4.conf.all.send_redirects=0</span><br><span class="line">net.ipv4.conf.eth0.send_redirects=0</span><br><span class="line">net.ipv4.conf.default.send_redirects=0</span><br><span class="line">5)     优化TCP协议栈</span><br><span class="line">打开TCP SYN cookie选项，有助于保护服务器免受SyncFlood攻击。</span><br><span class="line">net.ipv4.tcp_syncookies=1</span><br><span class="line"></span><br><span class="line">打开TIME-WAIT套接字重用功能，对于存在大量连接的Web服务器非常有效。</span><br><span class="line">net.ipv4.tcp_tw_recyle=1</span><br><span class="line">net.ipv4.tcp_tw_reuse=1</span><br><span class="line"></span><br><span class="line">减少处于FIN-WAIT-2连接状态的时间，使系统可以处理更多的连接。</span><br><span class="line">net.ipv4.tcp_fin_timeout=30</span><br><span class="line"></span><br><span class="line">减少TCP KeepAlive连接侦测的时间，使系统可以处理更多的连接。</span><br><span class="line">net.ipv4.tcp_keepalive_time=1800</span><br><span class="line"></span><br><span class="line">增加TCP SYN队列长度，使系统可以处理更多的并发连接。</span><br><span class="line">net.ipv4.tcp_max_syn_backlog=8192</span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>Copyright： </strong>
          
          Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2023/07/03/linux%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86-%E5%86%85%E6%A0%B8%E7%9A%84shmall%E5%92%8Cshmmax%E5%8F%82%E6%95%B0/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%86%85%E6%A0%B8%E5%8F%82%E6%95%B0/" rel="tag">内核参数</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2023/07/03/GBase8s%E6%95%B0%E6%8D%AE%E5%BA%93SQL%E8%AF%AD%E5%8F%A5%E8%80%97%E6%97%B6%E8%B7%9F%E8%B8%AA/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            GBase8s数据库SQL语句耗时跟踪
          
        </div>
      </a>
    
    
      <a href="/2023/06/23/GBase8s%E6%95%B0%E6%8D%AE%E5%BA%93Docker%E9%95%9C%E5%83%8F%E7%9A%84%E8%8E%B7%E5%8F%96%E4%B8%8E%E5%AE%9A%E5%88%B6%E4%BD%BF%E7%94%A8/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">GBase8s数据库Docker镜像的获取与定制使用</div>
      </a>
    
  </nav>

  
   
  
    
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2023-2024
        <i class="ri-heart-fill heart_icon"></i> Wang Wei
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ww.ico" alt="朝花夕拾"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->
 
<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: ".tocbot",
    contentSelector: ".article-entry",
    headingSelector: "h1, h2, h3, h4, h5, h6",
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: "main",
    positionFixedSelector: ".tocbot",
    positionFixedClass: "is-position-fixed",
    fixedSidebarOffset: "auto",
  });
</script>

<script src="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.staticfile.org/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.staticfile.org/clipboard.js/2.0.10/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
</body>

</html>